package org.cms.nio.main;

import java.io.IOException;
import org.cms.nio.NIOAcceptor;
import org.cms.nio.NIOReactorPool;
import org.cms.nio.NetSystem;
import org.cms.nio.bufferpool.SharedBufferPool;
import org.cms.nio.util.ConnectionFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @Description: 
 * @Department:
 * @author andy.lhc
 * @date 2016年6月1日 下午3:00:48 
 */
public class NIOServer {
  private static final Logger LOGGER = LoggerFactory.getLogger(NIOServer.class);
  
  public static final int PORT = 9999;
  
  /**
   * @param args
   */
  public static void main(String[] args) {
    SharedBufferPool sharedPool = new SharedBufferPool(1024 * 1024 * 100, 1024);
    new NetSystem(sharedPool) ;
    try {
      NIOReactorPool reactorPool = new NIOReactorPool("NIOServer_Reactor_Pool", 5, sharedPool);
      ConnectionFactory  factory = ConnectionFactory.getConnectionFactory();
      
      NIOAcceptor server = new NIOAcceptor("NioServer_Acceptor", "127.0.0.1", PORT, factory, reactorPool);
      server.start();
      // server started
      LOGGER.info(server.getName() + " is started and listening on " + server.getPort());
    } catch (IOException e) {
      LOGGER.error("error:",e);
    }
  }

}
